package com.chii.color.service.impl;

import com.chii.color.mapper.ColorHistoryMapper;
import com.chii.color.po.ColorHistory;
import com.chii.color.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private ColorHistoryMapper colorHistoryMapper;

    @Override
    public ColorHistory insertNewHistory(int userId, String input, String output) {
        ColorHistory history = new ColorHistory();
        history.setCreatedAt(new Date());
        history.setInput(input);
        history.setOutput(output);
        history.setUid(userId);
        colorHistoryMapper.insertSelective(history);
        return history;
    }

    @Override
    public List<ColorHistory> getByUserId(int uid) {
        return colorHistoryMapper.selectByUserId(uid);
    }

    @Override
    public int delById(int id) {
        return colorHistoryMapper.deleteByPrimaryKey(id);
    }


}
